package jjn.round1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jjn
 * @since 2022/10/11 00:21
 */
public class LeetCode1790_CheckOneSwapCanMakeStringEqual {
    public boolean areAlmostEqual(String s1, String s2) {
        int length1 = s1.length();
        int length2 = s2.length();
        if (length1 != length2) {
            return false;
        }
        List<Integer> indexes = new ArrayList<>();
        for (int i = 0; i < length1; i++) {
            if (s1.charAt(i) != s2.charAt(i)) {
                indexes.add(i);
            }
        }
        if (indexes.size() == 0) {
            return true;
        }
        if (indexes.size() != 2) {
            return false;
        }
        return s1.charAt(indexes.get(0)) == s2.charAt(indexes.get(1)) && s1.charAt(indexes.get(1)) == s2.charAt(indexes.get(0));
    }
}
